<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

  <!-- https -->
  <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=d021bae86db1d54dddc4071a5123749c"></script>
  <title>商铺地址</title>
  <script src="js/mui.min.js"></script>
  <link href="css/mui.min.css" rel="stylesheet" />
  <link href="css/map.css" rel="stylesheet" />
  <script type="text/javascript" charset="utf-8">
    mui.init()
  </script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>

<body>
  <div class="container">
    <div class="navbar">
      <div class="backBtn">
        <span class="mui-icon mui-icon-arrowleft"></span>
      </div>
      <span>商铺地址</span>
    </div>
    <div class="main">
      <div class="inputArea">
        <input name="" placeholder="输入店铺地址" id="" cols="30" rows="3"></textarea>
      </div>
      <div class="map">
        <div id="wrapper"></div>
      </div>
    </div>
    <div class="btnBox">
      <button>保存地址</button>
    </div>
  </div>

  <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=d021bae86db1d54dddc4071a5123749c"></script>
  <script>
    // window.onload = function () {
    //   var map = new AMap.Map('wrapper')
    // }
    var map = new AMap.Map("wrapper", {
        resizeEnable: true
    });
    var geocoder = new AMap.Geocoder();
    var marker = new AMap.Marker();
    function geoCode() {
        var address  = document.getElementById('address').value;
      console.log(address);
        geocoder.getLocation(address, function(status, result) {
            if (status === 'complete'&&result.geocodes.length) {
                var lnglat = result.geocodes[0].location
                document.getElementById('lnglat').value = lnglat;
                marker.setPosition(lnglat);
                map.add(marker);
                map.setFitView(marker);
            }else{
                log.error('根据地址查询位置失败');
            }
        });
    }
    document.getElementById("geo").onclick = geoCode;
    document.getElementById('address').onkeydown = function(e) {
        if (e.keyCode === 13) {
            geoCode();
            return false;
        }
        return true;
    };
  </script>

</body>

</html>
